//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_menu\fn_openSelected.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_displayed","_fnc_access","_fnc_exec"];

if (GVAR(SelectedItem) >= 0 && GVAR(SelectedItem) < GVAR(number_items)) then {
	_displayed = GVAR(accessible_items) select GVAR(SelectedItem);
	if (IS_ARRAY(_displayed)) then {
		[] call FUNC(close);
		_fnc_access = {true};
		if (count _displayed > 3) then {
			_fnc_access = GETVAL(_displayed,1,{true});
		};
		if ([] call _fnc_access) then {
			_fnc_exec = {};
			if (count _displayed <= 3) then {
				_fnc_exec = GETVAL(_displayed,1,{});
			} else {
				_fnc_exec = GETVAL(_displayed,2,{});
			};
			_fnc_exec spawn {
				sleep 0.3;
				[] call _this;
			};
		};
	};
} else {
	[] call FUNC(close);
};
TRACE("End");
TMFPROFILERSTOP;
